package com.yunyao.web.controller;

import com.yunyao.common.dto.DeptTreeDto;
import com.yunyao.common.web.util.PageResult;
import com.yunyao.common.web.util.YResult;
import com.yunyao.framework.dto.dept.DeptDeleteDto;
import com.yunyao.framework.dto.dept.DeptSaveDto;
import com.yunyao.framework.dto.dept.DeptUpdateDto;
import com.yunyao.framework.service.DeptService;
import com.yunyao.framework.vo.dept.DeptTreeVO;
import com.yunyao.framework.vo.dept.DeptVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xingjishuai
 * @date 2024-07-16
 */
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    /**
     * 查询部门树结构列表
     *
     * 通过GET请求方式提供部门树结构数据，该方法作为控制器接收前端请求，并调用服务层处理业务逻辑
     *
     * @param deptTreeDto 部门树查询条件封装对象，用于传递查询参数
     * @return YResult<List<DeptTreeVO>> 返回一个YResult对象，其中包含部门树结构的列表数据
     *
     * 该方法不直接处理业务逻辑，而是将请求转发给deptService处理
     */
    @GetMapping("/tree")
    public YResult<List<DeptTreeVO>> treeList(DeptTreeDto deptTreeDto) {
        return deptService.treeList(deptTreeDto);
    }

    @GetMapping("/list")
    public YResult<PageResult<DeptVO>> pageList(DeptTreeDto deptTreeDto) {
        return deptService.pageList(deptTreeDto);
    }


    @GetMapping("/info")
    public YResult<DeptVO> detailInfo(DeptTreeDto deptTreeDto) {
        return deptService.getDetailInfo(deptTreeDto);
    }
    @PostMapping("/add")
    public YResult<String> add(@RequestBody DeptSaveDto saveDto) {
        return deptService.add(saveDto);
    }
    @PostMapping("/update")
    public YResult<String> update(@RequestBody DeptUpdateDto updateDto) {
        return deptService.update(updateDto);
    }
    @PostMapping("/delete")
    public YResult<String> delete(@RequestBody DeptDeleteDto deleteDto) {
        return deptService.delete(deleteDto);
    }

}
